﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class SortAndFindElement
{
    static void Main()
    {
        Console.Write("Enter N: ");
        int arrayLength = int.Parse(Console.ReadLine());
        Console.Write("Enter K: ");
        int numberK = int.Parse(Console.ReadLine());
        int[] numbers = new int[arrayLength];

        Random randomNumber = new Random();

        for (int counter = 0; counter < numbers.Length; counter++)
        {
            Console.Write("Enter number {0}:\t", counter + 1);
            numbers[counter] = int.Parse(Console.ReadLine());

        }

        Array.Sort(numbers);
        

        //foreach (var number in numbers)
        //{
        //    Console.WriteLine(number);
        //}

        int index = Array.BinarySearch(numbers, numberK);
        if (index < 0)
        {
            Console.WriteLine("First element <= numberK: {0}", numbers[~index-1]);

        }
        else
        {
            Console.WriteLine("First element <= {0}: {1}", numberK, numbers[index]);

        }

    }
}
